﻿using System.Collections.Generic;
using Prism.Events;
using Prism.Ioc;
using Prism.Navigation.Regions;

namespace Prism.Dragablz.Extensions.Regions;

public class TabablzControlRegion : Region
{
    public TabablzControlRegion()
    {

    }

    private IEventAggregator _eventAggregator = null;
    public IEventAggregator EventAggregator
    {
        get
        {
            if (_eventAggregator == null) _eventAggregator = ContainerLocator.Current.Resolve<IEventAggregator>();
            return _eventAggregator;
        }
    }

    public override IRegionManager Add(object view, string viewName, bool createRegionManagerScope)
    {
        TabablzProxy md = view as TabablzProxy;
        IRegionManager rm = null;
        rm = base.Add(view, viewName, createRegionManagerScope);

        return rm;
    }

    private readonly Dictionary<object, TabablzProxy> _tabablzProxyDictionary = new Dictionary<object, TabablzProxy>();
    private Dictionary<object, TabablzProxy> TabablzProxyDictionary
    {
        get { return _tabablzProxyDictionary; }
    }

    public TabablzProxy GetTabablzProxy(object view)
    {
        if (!TabablzProxyDictionary.TryGetValue(view, out TabablzProxy value)) return null;
        return value;
    }

    public void AddTabablzProxy(object view, TabablzProxy proxy)
    {
        TabablzProxyDictionary.Add(view, proxy);
    }

    public void RemoveTabablzProxy(object view)
    {
        TabablzProxyDictionary.Remove(view);
    }
}
